#ifndef  __M2_CTRL_H__
#define  __M2_CTRL_H__

#include <stdint.h>

#ifdef __cplusplus
extern "C"
{
#endif

typedef enum 
{
	M2_INIT			= 0,
	M2_RUN			= 1,   
	M2_STOP			= 2, 
	M2_BRAKE		= 3,
	M2_FAULT		= 4,
	M2_UNKNOWN = 0xff
}M2States;

typedef enum 
{
	M2_FULLBACK			= 0,
	M2_UPBACK			= 1,   
	M2_DOWNBACK			= 2, 
	M2_SHORTUP			= 3,
	M2_SHORTDOWN			= 4,
	M2_LONGUP			= 5,
	M2_LONGDOWN			= 6,
	M2_READY			= 7,
	M2_RESET			= 8,
}ENUM_M2_MODE;

typedef struct
{
	uint8_t			RunStop	:1;
	uint8_t			MotorBack		:1;
	uint8_t			MotorFR;
	uint8_t			MotorFR_Pre;
	uint8_t			HallLimit_CW;
	uint8_t			HallLimit_CCW;
	uint8_t			BackResetFlag;

}struct_M2_Flag;

#define CCW_HALL_AD_MAX		200
#define CCW_HALL_AD_MIN		0

#define CW_HALL_AD_MAX		4000
#define CW_HALL_AD_MIN		3000

#define		UPBACK_RUNTIME		(13000)//(35784/2)
#define		DOWNBACK_RUNTIME		(13000)//(35784/2)
#define	SHORT_RUNTIME		(500)
#define LONG_RUNTIME		(500)

void M2_Init(void);
void M2_Task_1ms(void);

extern volatile M2States M2_STATE;
extern volatile struct_M2_Flag M2_Flag;
extern volatile ENUM_M2_MODE M2_mode;
extern volatile uint32_t M2_BackRunTime;
extern volatile uint32_t M2_ManualRunTime;

#ifdef __cplusplus
}
#endif

#endif // __M2_CTRL_H__

